from django.db import models

# Create your models here.


class bookinfo(models.Model):
    """图书，一对多的一"""

    btitle = models.CharField(max_length=20, verbose_name='书名')
    bpub_date = models.DateField(verbose_name='发布日期')
    bread = models.IntegerField(default=0, verbose_name='阅读量')
    bcomment = models.IntegerField(default=0, verbose_name='评论量')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')
    image = models.ImageField(upload_to='bookimage', verbose_name='封面', null=True)

    class Meta:
        db_table = 'bookinfo'
        verbose_name = '英雄'

    def __str__(self):
        return self.btitle


class heroinfo(models.Model):
    """图书  一对多 的 多"""

    GENDER_CHOISE = (
        (0, 'male'),
        (1, 'female')
    )

    hname = models.CharField(max_length=20, verbose_name="名字")
    hgender = models.SmallIntegerField(choices=GENDER_CHOISE, verbose_name="性别")
    hdesc = models.CharField(max_length=200, null=True, verbose_name="介绍")
    hbook = models.ForeignKey(bookinfo, on_delete=models.CASCADE, verbose_name="评论量")  # 外键 hbook_id
    is_delete = models.BooleanField(default=False, verbose_name="逻辑删除")

    class Meta:
        db_table = 'heroinfo'
        verbose_name = '英雄'

    def __str__(self):
        return self.hname